﻿/* ----------------------------------------------------------------------------
 * Copyright (c) Rob Ashton 2009
 *
 * This source code is subject to terms and conditions of the Microsoft Public 
 * License (Ms-PL).
 * 
 * By using this source code in any fashion, you are agreeing to be bound 
 * by the terms of the Microsoft Public License.
 * 
 * To request a copy of the Microsoft Public License, send a request by email
 * to license@mvcex.com
 *
 * This notice must not be removed from this software.
 * ---------------------------------------------------------------------------- */

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using System.Web.Mvc;
using MvcEx.Controllers;

namespace MvcEx.Tests
{
    [TestFixture]
    public class MvcExControllerTests
    {
        [Test]
        public void derivedcontroller_view_no_args()
        {
            TestController controller = new TestController();           
            ViewResult result = (ViewResult)controller.Index();

            // Should remain clear
            Assert.AreEqual("", result.ViewName);
        }

        [Test]
        public void derivedcontroller_view_model()
        {
            TestController controller = new TestController();
            ViewResult result = (ViewResult)controller.SomeAction();

            // This value should be set
            Assert.AreEqual("SomeView", result.ViewName);
        }

        [Test]
        public void derivedcontroller_view_name_and_model()
        {
            TestController controller = new TestController();
            ViewResult result = (ViewResult)controller.Home();

            // These values should be set
            Assert.AreEqual("SomeOtherView", result.ViewName);
            Assert.AreEqual("StringModel", result.ViewData.Model);
        }


        public class TestActionContainer : MvcExActionContainer
        {
            public ActionResult Index()
            {
                return View();
            }

            public ActionResult SomeAction()
            {
                return View("SomeView");
            }

            public ActionResult Home()
            {
                return View("SomeOtherView", (Object)"StringModel");
            }
        }

        /// <summary>
        /// This would ordinarily be generated by the dynamic controller factory
        /// </summary>
        public class TestController : MvcExController
        {
            public ActionResult Index()
            {
                TestActionContainer container = new TestActionContainer();
                RegisterContainer(container);
                return container.Index();
            }

            public ActionResult Home()
            {
                TestActionContainer container = new TestActionContainer();
                RegisterContainer(container);
                return container.Home();
            }

            public ActionResult SomeAction()
            {
                TestActionContainer container = new TestActionContainer();
                RegisterContainer(container);
                return container.SomeAction();
            }
        }
    }
}
